const app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner:[],
    indicatorDots: false,
    autoplay: true,
    interval: 3000,
    duration: 500,
    indicatorColor:'rgba(0, 0, 0, .6)',
    classArr:[],
    CgalArr:[],
    intCurrPage:1,
    list:[],
    ProvName:'石家庄',
    intPageCount:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getAd1();
    this.getLocalWeizhi();
  },
  toSearch:function () {
    wx.navigateTo({
        url: 'search'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (this.data.intCurrPage < this.data.intPageCount) {
        this.setData({
            intCurrPage: that.data.intCurrPage + 1
        })
        this.FJ_Get_DisposeSYList();
    }    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  getAd1:function () {
    var that = this;
    app.getDaoPostN('api/FJDispose/FJ_Get_DisposeSY','{}',r =>{
        if (r.code == 200) {
          
          if (r.data.MK.length > 0) {
            for (var i = 0; i < r.data.MK.length; i++) {
              r.data.MK[i].Name = r.data.MK[i].Name.replace(/[\r\n]/g,"");
            }
          }
          
          that.setData({
            banner:r.data.Banner.ds,
            classArr:r.data.MK,
            CgalArr:r.data.Cgal.ds
          })
        }
        
    }) 
  },
  getLocalWeizhi:function () {
    var that = this;
    // wx.getLocation({
    //   success:function (res) {
    //     that.getweizhi(res.latitude,res.longitude);
    //   }
    // }) 
  },
  getweizhi: function(latitude, longitude) {
    var that = this;
    wx.request({
      url: `https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=${longitude},${latitude}&key=e24353dac4e7753f2eea4ce5e3112b2d`,
      header: {
        'Content-Type': 'application/json'
      },
      success: function(result) {
        var r = result.data;
        if (r.status == 0) {
          that.setData({
            ProvName:result.data.regeocode.addressComponent.province
          })
          that.FJ_Get_DisposeSYList()
        }else{
          that.FJ_Get_DisposeSYList()
        } 
      },
      fail: function(res) {
        that.FJ_Get_DisposeSYList();
      }
    })
  },  
  FJ_Get_DisposeSYList:function () {
    var that = this;
    var api_input = {
      intCurrPage:this.data.intCurrPage,
      ProvName:this.data.ProvName
    }
    wx.showToast({
      title: "信息加载中..",
      icon: "loading",
      duration: 100000
    })
    app.getDaoPostN('api/FJDispose/FJ_Get_DisposeSYList', api_input, r => {
        if (r.code == 200) {
            for (var i = 0; i < r.data.data.ds.length; i++) {
                if (r.data.data.ds[i].Photo) {
                    r.data.data.ds[i].Photo = r.data.data.ds[i].Photo.split('|')[0];
                }
            }
            var ds = r.data.data.ds;
            var words = that.data.list.concat(ds);
            that.setData({
                list: words,
                intPageCount: r.data.intPageCount,
                mores:true,
            })
            wx.hideToast();
        } else {
            wx.hideToast();
            app.tishi(r.message)
        }
        
    })    
  },
  toinfo: function(e) {
      wx.navigateTo({
          url: 'detailed?id=' + e.currentTarget.dataset.id
      })
  }, 
  tolist:function (e) {
      wx.navigateTo({
          url: 'list?id=' + e.currentTarget.dataset.id + '&lev='+e.currentTarget.dataset.lev + '&name=' + e.currentTarget.dataset.name
      })  

  },
  toMyUser:function () {
    if (app.checkFjLogin()) {
      wx.navigateTo({
        url: '../user/index'
      }) 
    } else {
      wx.navigateTo({ url: '../../pages/login/index' });
    }  
  },
  toMyRuzhu:function () {
    if (app.checkFjLogin()) {
      wx.navigateTo({
        url: '../user/mywyczsp'
      }) 
    } else {
      wx.navigateTo({ url: '../../pages/login/index' });
    }  
  }
})